<?

if ($c = stack('name')) {

	$_id_component	= $DATA['components'][$c]['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value
	
	$_crit = "id_data=$_id_data AND id_parent=$_id_component AND attr & ".AA_VISIBLE;


	$s = array_extend( array('per_page' => 10, 'caption' => '', 'prev_link' => '&larr;&nbsp;Previous&nbsp;page', 'next_link' => '&larr;&nbsp;Next&nbsp;page'), $DATA['components'][$c]['settings']);

	$s['per_page'] = (int)$s['per_page'];

	
	$num = datafetch('db_item', tb('data'), $_crit, "COUNT(*) as num");


	if ($num = (int)$num['num']) {
	
		$DATA['components'][$c]['settings']['paging'] = createPaging(array(
			'num' => $num, 'page' => param('page'), 'perPage' => $s['per_page'], 'titlePrev' => $s['prev_link'], 'titleNext' => $s['next_link'], 'generate' => 'prev, next'));
		
		$DATA['components'][$c]['settings']['paging']['data'] = array_mark_bounds($DATA['components'][$c]['settings']['paging']['data']);
	
		$limit = array(($DATA['components'][$c]['settings']['paging']['page'] - 1) * $s['per_page'], $s['per_page']);
	}


	$DATA['components'][$c]['data'] = array_mark_bounds( datafetch_array('db_list', array('table' => tb('data'), 'where' => "$_crit",	'order' => 'id_index', 'index' => 'id', 'limit' => $limit )));

	foreach($DATA['components'][$c]['data'] as $k => $v)
		$DATA['components'][$c]['data'][$k] = array_merge($v, datafetch_array('meta', $_id_meta, $k, $CONTEXT['lang']));

//	debug($DATA['components'][$c]);
//	exit;

//	$DATA['components'][$c]['data'] = datafetch_array('gallery', FP_UPLOAD_PATH.$DATA['components'][$c]['settings']['path']);	// load existing images list
	
	$GLOBALS['SP']--;
}

?>